import request from "@/utils/request";
import type {
  GetSpuListApiParams,
  GetSpuListApiResponse,
  BaseSaleAttrList,
  SpuImageList,
  SpuSaleAttrList,
  AddOrUpdateSpuParams,
} from "./model/spuModel";

const enum API {
  getSpuList = "/admin/product",
  getSpuSaleAttrList = "/admin/product/baseSaleAttrList",
  addSpuList = "/admin/product/saveSpuInfo",
  getSpuImageList = "/admin/product/spuImageList",
  getSpuAttrList = "/admin/product/spuSaleAttrList",
  updateSpu = "/admin/product/updateSpuInfo",
  deleteSpu = "/admin/product/deleteSpu",
}

/**
 * 获取Spu数据列表
 * @param param0
 * @returns
 */
export const getSpuListApi = ({
  page,
  limit,
  category3Id,
}: GetSpuListApiParams) => {
  return request.get<any, GetSpuListApiResponse>(
    API.getSpuList + `/${page}/${limit}`,
    {
      params: {
        category3Id,
      },
    }
  );
};

/**
 * 获取销售属性列表
 * @returns
 */
export const getSpuSaleAttrListApi = () => {
  return request.get<any, BaseSaleAttrList>(API.getSpuSaleAttrList);
};

/**
 * 添加Spu属性
 * @param data
 * @returns
 */
export const addSpuListAPi = (data: AddOrUpdateSpuParams) => {
  return request.post<any, null>(API.addSpuList, data);
};

// 获取Spu图片列表
export const getSpuImageListApi = (id: number) => {
  return request.get<any, SpuImageList>(API.getSpuImageList + `/${id}`);
};

// 获取Spu销售属性列表
export const getSpuAttrListApi = (id: number) => {
  return request.get<any, SpuSaleAttrList>(API.getSpuAttrList + `/${id}`);
};

// 更新Spu数据
export const updateSpuApi = (data: AddOrUpdateSpuParams) => {
  return request.post<any, null>(API.updateSpu, data);
};

// 删除Spu属性
export const deleteSpuApi = (id: number) => {
  return request.delete<any, null>(API.deleteSpu + `/${id}`);
};
